<template>
  <section style="margin-bottom:120px;">
    <!--工具条-->
    <PaperToolbar
    ref="_PaperToolbar"
      :buttonList="buttonList"
      :cateogryParam="cateogryParam"
      @callFunction="callFunction"
    >
    </PaperToolbar>
        <el-pagination
      layout="prev, pager, next"
      @current-change="handleCurrentChange"
      :page-size="page.PageSize"
      :total="page.PageCount"
      style="float: right"
    >
    </el-pagination>
    <el-table
      :data="tableData"
      highlight-current-row
      v-loading="listLoading"
      style="width: 100%"
      ref="mytable"
      @row-click="clickRow"
      @row-contextmenu="rowContextmenu"
    >
      <el-table-column type="selection" width="50"> </el-table-column>
      <el-table-column label="序号" width="70px">
        <template slot-scope="scope">
          {{ (page.PageIndex - 1) * page.PageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
       <el-table-column
        prop="Title"
        label="试卷名称"
        width="350"
      >
      
      </el-table-column>
             <el-table-column
        prop="PaperTypeText"
        label="试卷类型"
        width="150"
      >     
      </el-table-column>
       <el-table-column
        prop="Year"
        label="年份"
        width="90"
      ></el-table-column>
        <el-table-column
        prop="ExamTime"
        label="考试时长"
        width="100"
      ></el-table-column>
              <el-table-column
        prop="Score"
        label="总分"
        width="100"
      ></el-table-column>
                    <el-table-column
        prop="PassScore"
        label="合格分数"
        width="100"
      ></el-table-column>
      <el-table-column
        prop="IsRecommend"
        label="是否推荐"
        width="100"
      >
      <template slot-scope="scope">
        {{scope.IsRecommend? "是":"否" }}
      </template>
      </el-table-column>

      <el-table-column
        prop="IsNew"
        label="是否新试卷"
        width="100"
      >
      <template slot-scope="scope">
        {{scope.IsNew? "是":"否" }}
      </template>
      </el-table-column>
      <el-table-column
        prop="IsVip"
        label="是否VIP"
        width="100"
      >
      <template slot-scope="scope">
        {{scope.IsVip? "是":"否" }}
      </template>
      </el-table-column>
      <el-table-column
        prop="FromSource"
        label="来源"
        width="120"
      >
      </el-table-column>
      <el-table-column
        prop="InsertTime"
        label="添加时间"
        width="220"
      >
      </el-table-column>
    </el-table>
        <el-pagination
      layout="prev, pager, next"
      @current-change="handleCurrentChange"
      :page-size="page.PageSize"
      :total="page.PageCount"
      style="float: right"
    >
    </el-pagination>
  <context-button v-if="menuVisible" @foo="foo" ref="contextbutton" @handleOne="handleOne" @handleTwo="handleTwo" @handleThree="handleThree">
  </context-button>
  </section>
</template>

<script>
import util from "../../../util/date";
import contextButton from '../../components/menu/papermenu.vue'
import {showPaperText} from '../../api/helpEnum'
import {
  getCategoryList,
staticPaperEnumList,
getPaperList
} from "../../api/api";
import { getButtonList } from "../../promissionRouter";
import PaperToolbar from "../../components/PaperToolbar.vue";
import qs from "qs"
export default {
  components: { PaperToolbar,contextButton },
  data() {
    return {
      menuVisible: false,
      buttonList: [],
      paperEnumList:[],
      tableData: [],
      allcategory:[],
      categoryData: [],
      select: {},
     cateogryParam:{
         categoryBase:"1277",
         categoryChild:"1004",
         categoryNode:"1188",
    },
      addFormRules: {
        name: [{ required: true, message: "请填写章节名称", trigger: "blur" }],
      },
      page: {
        PageSize: 10,
        PageIndex: 1,
        PageCount: 0,
        Where: "",
      },
      paperParam:{
        year:0,
        title:'',
        paperType:0,
        cateGoryID:'',
      },
      listLoading: false,
      addDialogFormVisible: false,
      addFormVisible: false, //新增界面是否显示
      addLoading: false,
      addForm: {
        name: "",
        isEnabled: true,
        pid: "",
        sequence: 0,
        rootID: "",
      }
    };
  },
  methods: {
    clickRow: function (row) {
      this.select = row;
      this.$refs.mytable.clearSelection();
      this.$refs.mytable.toggleRowSelection(row);
    },
    callFunction(item) {
      this.paperParam.paperType = item.paperType;
      this.paperParam.title=item.search;
      this.page.Where=item.search;
      this.paperParam.year=item.currentYear;
      if(item.Func=='search')
      {
         this.page.PageIndex=1;
      }
      this[item.Func].apply(this, item);
    },
    handleCurrentChange(val) {
      this.page.PageIndex = val;
      this.search();
    },
    initCatalog () {
      let param = {};
      getCategoryList(param).then((data) => {
        if (data.IsSuccess) {
          this.categoryData =data.Data.TreeData;
          this.allcategory=data.Data.AllData;
          this.$refs._PaperToolbar._initCateogry(this.categoryData);
        }
      });
    },
    initPaperEnumlist()
    {
      staticPaperEnumList().then((data)=>{
      this.paperEnumList=data;
      });
    },
    search()
    {
      this.paperParam.Page=this.page
      this.paperParam.cateGoryID=this.cateogryParam.categoryNode||this.cateogryParam.categoryChild || this.cateogryParam.categoryBase;
      let _param = Object.assign({}, this.paperParam);
      getPaperList(_param).then((res)=>{
          if(res.data.IsSuccess)
          {
            this.tableData=res.data.Data.Data;
            this.page.PageCount=res.data.Data.PageCount;
          }
      });

    },
    rowContextmenu (row, column, event) {
        this.select = row;
        this.$refs.mytable.clearSelection();
        this.$refs.mytable.toggleRowSelection(row);
        this.menuVisible = false
        this.menuVisible = true
        // 阻止右键默认行为
        event.preventDefault()
        this.$nextTick(() => {
          this.$refs.contextbutton.init(row,column,event)
        })
      },
      foo() { // 取消鼠标监听事件 菜单栏
        this.menuVisible = false
        document.removeEventListener('click', this.foo)
      },
      handleOne () {
        console.log('点击菜单一')
      },

      handleTwo () {
        console.log('点击菜单二')
      },
      handleThree () {
        console.log('点击菜单三')
      },
  },
  mounted() {
  this.initCatalog ();
  this.search();
  console.info(showPaperText(1));
    let routers = window.localStorage.router
      ? JSON.parse(window.localStorage.router)
      : [];
    this.buttonList = getButtonList(this.$route.path, routers);
  },
};
</script> 

<style scoped>
</style>